<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'/includes/site_defaults.php');
	
	$dealer = $_SESSION['dealer'];
	// $seller = $_SESSION['seller'];
	$seller = false;
	
	mysql_select_db($db_name, $db);
	
	if ($dealer) {
		$qry = "SELECT 
			id, dealer_name, city, state_province, phone, num_views, description 
			FROM dealerships 
			WHERE contact_id = ".$_SESSION['id'];
		$dealerships = mysql_query($qry) or die(mysql_error());
		
		$dealer = mysql_num_rows($dealerships) > 0;
	}
	
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>Admin</title>
	<link href="<?php echo $site_root."css/green.css"; ?>" rel="stylesheet" type="text/css" />
	<link href="<?php echo $site_root."css/validation.css"; ?>" rel="stylesheet" type="text/css" />
	<script src="<?php echo $site_root."js/jquery.js" ?>" type="text/javascript" charset="utf-8"></script>
	<script src="<?php echo $site_root."js/jquery-ui.js" ?>" type="text/javascript" charset="utf-8"></script>
	<script src="<?php echo $site_root."js/lib/jquery.form.js" ?>" type="text/javascript" charset="utf-8"></script>
	<script src="<?php echo $site_root."js/jquery.validate.js" ?>" type="text/javascript" charset="utf-8"></script>
	
	
	<script type="text/javascript" charset="utf-8">
		function showDealership(id) {
			var dataString = "";
			if (id > 0) {
				dataString = "id="+id;
			}

			$.get("edit_dealer.php", dataString, function(data) {
				 	$("#newdealer").html(data).slideDown("slow");
					$("#dealer_name").focus();
				}, "html");
			
		};
		
		function deleteDealership(id) {
			var dataString = "id="+id;
			$.get("delete_dealer.php", dataString, function(data){
				location.reload();
			}, "html");
		}
	</script>
	
	
	
</head>

<body>
	<?php include($header); ?>
	<?php include($navigation); ?>
	<div id="wrapper">
		<div id="contentcontainer">
			<div id="leftcol">
				<div id="leftcolcontain">
					<ul>
						<li><a href="edit_dealer.php" onclick="showDealership(); return false;">Add Dealership</a></li>
						<!-- <li><a href="" onclick="">Add Classified Ad</a></li> -->
						
					</ul>
				</div><!--End of Left Column Container-->
			</div><!--End of Left Column-->

			<div id="rightcol">
				<div id="rightcolcontain">
					
				</div><!--End of Right Column Container--> 
			</div><!--End of Right Column-->

			<div id="content">
				<div id="contentcontain">
				<?php if ($dealer): ?>
                <div id="mydealers">
                <h4>Your Dealerships</h4>
                <table>
                	<tr>
                    	<th>Dealer</th>
                        <th>Location</th>
                        <th>Phone Number</th>
                        <th>Views</th>
                        <th>Actions</th>
                    </tr>
					
					<?php while ($dealer = mysql_fetch_assoc($dealerships)) { ?>

                    <tr>
                    	<td><?php echo $dealer['dealer_name'] ?></td>
                        <td><?php echo $dealer['city'].', '.$dealer['state_province'] ?></td>
                        <td><?php echo $dealer['phone'] ?></td>
                        <td><?php echo $dealer['num_views'] ?></td>
                        <td style="text-align: center; white-space: nowrap;">
                        	<a 
								href="edit_dealer.php?id=<?php echo $dealer['id'] ?>" 
								onclick="showDealership(<?php echo $dealer['id'] ?>); return false;"
							>								
								<img src="<?php echo $images."edit.png" ?>" alt="Edit Dealership" title="Edit Dealership"/>
							</a>                        
							<a 
								href="delete_dealer.php?id=<?php echo $dealer['id'] ?>" 
								onclick="deleteDealership(<?php echo $dealer['id'] ?>); return false;"
							>
								<img src="<?php echo $images."delete.png" ?>" alt="Delete Dealership" title="Delete Dealership"/>
							</a>
						</td>     
                    </tr>
                    <?php } 
						mysql_free_result($dealerships);
					?>
                </table>
                
                
                </div>
				<?php endif; ?>
				<div id="newdealer" style="display:none"></div>
				<?php if ($seller): ?>	

				<div id="currentad"> 
					<h4>Your Ads</h4>               
                <table>
                	<tr>
                    	<th>AD</th>
                        <th>Price</th>
                        <th># of Views</th>
                        <th>Expiration</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                    </tr>
                    <tr>
                    	<td>Oscar Meyer Wiener Mobile</td>
                        <td>$100</td>
                        <td>213</td>
                        <td>today</td>
                        <td><a href="/"><img src="../images/renew.png" alt="Icon for renew button" /></a></td>
                        <td><a href="/"><img src="../images/edit.png" alt="Icon for edit button" /></a></td>
                        <td><a href="/"><img src="../images/delete.png" alt="Icon for delete button" /></a></td>     
                    </tr>
                    
                    <tr>
                    	<td>Batmobile</td>
                        <td>$2000</td>
                        <td>51</td>
                        <td>tomorrow</td>
                        <td><a href="/"><img src="../images/renew.png" alt="Icon for renew button" /></a></td>
                        <td><a href="/"><img src="../images/edit.png" alt="Icon for edit button" /></a></td>
                        <td><a href="/"><img src="../images/delete.png" alt="Icon for delete button" /></a></td>     
                    </tr>
                </table>
                </div>
                <?php endif; ?>

                <div id="newad"></div>
                
				
                
                

				</div><!--End of Content Contain-->    
			</div><!--End of Content-->

		</div><!--End of Content Container-->
	</div><!--End of Wrapper-->
	<?php include($footer); ?>
	

</body>
</html>
